from csagent.core.node.base_node import BaseNode
from csagent.core.context import AgentState
from openai import OpenAI
import time
import os
import copy
class Node(BaseNode):
    def initialize(self):
        """初始化节点"""
        print(self.conf)
        print(f"{self.node_config.name}初始化成功")
    
    def execute(self, state: AgentState, stream_writer=None) -> AgentState:
        print(f"{self.node_config.name}开始执行")
        tool_call = state["node_context"]["messages"][-1]['tool_calls'][0]
        function_name = tool_call['function']['name']
        args = tool_call['function']['arguments']
        print(f"执行{function_name}工具调用，args:{args}")
        
        #模拟大模型调用过程
        time.sleep(1)
        state["node_context"]["messages"].append(
            {
                "role":"tool", 
                "content":'{\"res\":\"call res\"}',
                "tool_call_id":tool_call['id']
            }
        )
        return state